package io.mybatis.example.springboot.controller;

import io.mybatis.common.core.DataResponse;
import io.mybatis.common.core.RowsResponse;

import io.mybatis.example.springboot.model.SysRoleMenu;
import io.mybatis.example.springboot.service.SysRoleMenuService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * sys_role_menu - 角色和菜单关联表
 *
 * @author mkj
 */
@RestController
@RequestMapping("sysRoleMenus")
public class SysRoleMenuController {

  @Autowired
  private SysRoleMenuService sysRoleMenuService;

  @PostMapping
  public DataResponse<SysRoleMenuDO> save(@RequestBody SysRoleMenuDO sysRoleMenu) {
    return DataResponse.ok(sysRoleMenuService.save( sysRoleMenu));
  }

  @GetMapping
  public RowsResponse<SysRoleMenuDO> findList(@RequestBody SysRoleMenuDO sysRoleMenu) {
    return RowsResponse.ok(sysRoleMenuService.findList( sysRoleMenu));
  }

  @GetMapping(value = "/{id}")
  public DataResponse<SysRoleMenuDO> findById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysRoleMenuService.findById(id));
  }

  @PutMapping(value = "/{id}")
  public DataResponse<SysRoleMenuDO> update(@PathVariable("id") Long id, @RequestBody SysRoleMenuDO sysRoleMenu) {
    sysRoleMenu.setId(id);
    return DataResponse.ok(sysRoleMenuService.update( sysRoleMenu));
  }

  @DeleteMapping(value = "/{id}")
  public DataResponse<Boolean> deleteById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysRoleMenuService.deleteById(id) == 1);
  }

}
